/**
 * Created by 55456 on 2016/4/12.
 */
var shortDataTypes = require("../lib/sequelizex").DataTypes;
module.exports = (sequelize,DataTypes) => {
    return sequelize.define("Msg",{
        updatedAt:shortDataTypes.String(),
        createdAt:shortDataTypes.String(),
        content : shortDataTypes.Text()
    },{
        timestamps:false,
        hooks:{
            beforeCreate:function(msg){
                msg.createdAt = Math.round(new Date().getTime()/1000);
                msg.updatedAt = Math.round(new Date().getTime()/1000);
            },
            beforeUpdate:function(msg){
                msg.updatedAt = Math.round(new Date().getTime()/1000);
            }
        },
        associate : function(models){
            models.Msg.belongsTo(models.User,{as:'sendMsg',foreignKey:'sendID'});
            models.Msg.belongsTo(models.User,{as:'revMsg',foreignKey:'revID'});
        }
    });
};
